"""
# -*- coding: utf-8 -*-
# @Time    : 2023/10/8 8:39
# @Author  : 王摇摆
# @FileName: test.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import  pandas as pd
from train import model

'''
先对测试集中的数据形状进行简单调整
1. 在测试集上进行模型预测
'''
test_data = pd.read_csv('dataset/test.csv')
# 提取特征，注意这里不需要 'id' 列
X_test = test_data.drop(['id'], axis=1).values
# 调整输入形状
X_test = X_test.reshape(X_test.shape[0], X_test.shape[1], 1)

pred = model.predict(X_test)
pred = pred.flatten()
print('【模型已预测完毕】')

'''
2. 将预测结果输出为CSV文件'''
# 将概率值转换为类别标签
threshold = 0.5
pred_binary = (pred > threshold).astype(int)

pd.DataFrame({'id': test_data['id'], 'target': pred_binary}).to_csv('result/cnn_with_channel_attention.csv', index=None)
print('【预测结果已输出为CSV文件】')
